﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using GPSTracker.Helper;
using System.Text;

namespace GPSTracker.Views.DAL
{
    public class ProductDAL
    {
        public DataTable FillProductMasterGrid(string strProductID)
        {
            var sb = new StringBuilder();
            var dt = new DataTable();

            if (strProductID == string.Empty)
            {
                var strSQL = "SELECT * FROM dbo.VW_GetProduct WHERE ISNULL(IsActive,0) = 1";
                var da = new SqlDataAdapter(strSQL, CommonFx.GetSqlCon());
                da.Fill(dt);
            }
            else
            {
                sb.Append("SELECT * FROM dbo.VW_GetProduct WHERE ProductID = '" + strProductID + "' AND ISNULL(IsActive,0) = 1");
                var da = new SqlDataAdapter(sb.ToString(), CommonFx.GetSqlCon());
                da.Fill(dt);
            }
            return dt;
        }

        public void DeleteProductMaster(string strProductID)
        {
            var sb = new StringBuilder();
            sb.Append("UPDATE dbo.M_Product SET IsActive = 0 WHERE ProductID = '" + strProductID + "' ");

            var cmd = new SqlCommand(sb.ToString(), CommonFx.GetSqlCon());
            cmd.ExecuteNonQuery();
        }
    }
}
